package com.hlf.common.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 微信模板消息枚举类
 * @author PanJialong
 * @date 2017年3月8日 下午2:58:14
 */
public enum WechatTemplateEnum {
    
    /**
     * 支付成功模板
     */
    PAY_SUCCESS("支付成功模板消息", "wechat_pay_tmpl"),
    BIND_SUCCESS("绑定成功模板消息", "wechat_bind_tmpl"),
    UNBIND_SUCCESS("解绑成功模板消息", "wechat_unbind_tmpl"),
    MEMBER_LV_CHANGE("会员等级变更模板消息", "memberLV_change_tmpl");

    private WechatTemplateEnum(String desc, String value) {
        this.desc = desc;
        this.value = value;
    }

    /* 枚举值 */
    private String value;
    /* 描述 */
    private String desc;

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    public static WechatTemplateEnum getEnum(String value) {
        WechatTemplateEnum resultEnum = null;
        WechatTemplateEnum[] enumAry = WechatTemplateEnum.values();
        for (int i = 0; i < enumAry.length; i++) {
            if (enumAry[i].getValue().equals(value)) {
                resultEnum = enumAry[i];
                break;
            }
        }
        return resultEnum;
    }

    public static List<Map<String, String>> toList() {
        WechatTemplateEnum[] ary = WechatTemplateEnum.values();
        List<Map<String, String>> list = new ArrayList<>();
        for (int i = 0; i < ary.length; i++) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("value", String.valueOf(ary[i].getValue()));
            map.put("desc", ary[i].getDesc());
            list.add(map);
        }
        return list;
    }

    public static Map<String, Map<String, Object>> toMap() {
        WechatTemplateEnum[] ary = WechatTemplateEnum.values();
        Map<String, Map<String, Object>> enumMap = new HashMap<String, Map<String, Object>>();
        for (int num = 0; num < ary.length; num++) {
            Map<String, Object> map = new HashMap<String, Object>();
            String key = String.valueOf(getEnum(ary[num].getValue()));
            map.put("value", String.valueOf(ary[num].getValue()));
            map.put("desc", ary[num].getDesc());
            enumMap.put(key, map);
        }
        return enumMap;
    }
}
